package org.abc.fund.controller.strategy.response;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import org.abc.fund.entity.strategy.StrategyAdjustmentHistory;

@Data
@Builder
public class StrategyAdjustmentHistoryResponse {
  private Long id;
  private Long strategyId;
  private String reason;
  private List<AdjustmentDetailResponse> details;
  private LocalDate createdAt;

  public static StrategyAdjustmentHistoryResponse fromEntity(StrategyAdjustmentHistory history) {
    if (history == null) return null;
    return StrategyAdjustmentHistoryResponse.builder()
        .id(history.getId())
        .strategyId(history.getStrategy() != null ? history.getStrategy().getId() : null)
        .reason(history.getReason())
        .createdAt(history.getCreatedAt())
        .details(
            history.getDetails() == null
                ? Collections.emptyList()
                : history.getDetails().stream()
                    .map(AdjustmentDetailResponse::fromEntity) // 方法引用
                    .collect(Collectors.toList()))
        .build();
  }
}
